#!/usr/bin/env python
# encoding: utf-8
'''
@author: toby
@license: (C) Copyright 2013-2017, Node Supply Chain Manager Corporation Limited.
@contact: hejunwang01@126.com
@software: pycharm
@file: pytest_run.py
@time: 2021-04-25 0:21
@desc:
'''


import  pytest,os,time
TESECASE_PATH = "/root/flask-celery-hjw/flask-celery/pytest_pkg/test_case"
# TESECASE_PATH = "D:/flask-celery-py3/pytest_pkg/test_case"
base_path = os.path.dirname(os.path.dirname(__file__))  # 项目基本路径

import logging
logger = logging.getLogger(__name__)
def get_time():

    time_str = time.strftime('%Y-%m-%d-%H-%M-%S')
    return time_str

class StartRun:

    def runcase(self):
        logger.info("回归模式API,开始执行✈✈✈")
        print("pytest base_path-->:",os.getcwd())
        '''
        当pytest.ini已配置addopts = -v时，py文件里执行pytest.main(["test_001_rights.py"])或cmd下执行pytest，
        未带-v，就会以配置的方式去执行，结果有详细的信息
        '''
        pytest.main(['-v',
                     '-rs',
                     '--html=/root/flask-celery-hjw/flask-celery/pytest_pkg/reports/{}_XLR_API_report.html'.format(get_time()),
                     '--self-contained-html',
                     "--capture=sys",
                     TESECASE_PATH])
        # pytest.main([TESECASE_PATH])


        print('*'*100)
        logger.info("运行结束 ,开始生成报告 !")






if __name__ == '__main__':
       #方式一   可以成功
    # pytest.main()
    print("从main开始执行脚本:")
    print(get_time())
    print(os.path.join(os.path.dirname(__file__)))
    # 方式二  allure 需要使用jdk1.8
    # pytest.main(['--alluredir','report1/result',TESECASE_PATH])     # 生成测试报告json
    # 将测试报告换成html格式，
    # split ="allure“+” generate"+"./report1/result"+"-o "+ "./report1/html"+"--clean"
    # os.system(split)
    # 方式三
    print("base_path:-->",base_path)
    StartRun().runcase()
